package org.apaydin.eksisozluk;

public class EksiTopic {
    private final String href;
    private final String text;
    private final EksiItems eksiItems;

    public EksiTopic(String text) {
        this("show.asp?t=" + text.replace(" ", "+"), text);
    }

    public EksiTopic(String href, String text) {
        this.href = href;
        this.text = text;
        eksiItems = new EksiItems(this);
    }

    public String getHref() {
        return href;
    }

    public String getText() {
        return text;
    }

    public EksiItems getEksiItems() {
        return eksiItems;
    }

    @Override
    public String toString() {
        return "EksiTopic{" +
                "href='" + href + '\'' +
                ", text='" + text + '\'' +
                '}';
    }

    private Fetcher<EksiTopic> fetcher = new ItemFetcherImpl();

    public void fetch(int page) {
        try {
            fetcher.fetch(this, page);
        } catch (Exception e) {
            throw new EksiException(e.getMessage(), e);
        }
    }

    public EksiItem get(int index) {
        return getEksiItems().getItems().get(index);
    }
}
